package com.truthbean.jeetb.utils.web.invoker;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.awt.*;
import java.awt.image.BufferedImage;

//GetScreen
public class GcInvoker extends DefaultInvoker {
    public boolean doBefore() {
        return false;
    }

    public boolean doAfter() {
        return false;
    }

    public void invoke(HttpServletRequest request, HttpServletResponse response, HttpSession session) throws Exception {
        try {
            Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
            Rectangle rec = new Rectangle(0, 0, (int) size.getWidth(), (int) size.getHeight());
            BufferedImage img = new Robot().createScreenCapture(rec);
            response.setContentType("image/jpeg");
            ImageIO.write(img, "jpg", response.getOutputStream());
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }
}